begintownscript;

variables;
short creature_count = 0;
short choice = 0;
short pc_counter = 0;
short lead_char = 0;
short death_toll = 0;
short who_heals = 0;
string healer;
string angry;

body;

beginstate 0; //INIT_STATE
	set_crime_tolerance(2);

	//Shunt the script to a new state, depending on the entry flag
	//(5,1). Flag gets reset to zero before the state changes.


	if(get_flag(5,1) == 1) {
		set_flag(5,1,0);
		set_state_continue(20);
		}
	if(get_flag(5,1) == 2) {
		set_flag(5,1,0);
		set_state_continue(30);
		}
	if(get_flag(5,1) == 3) {
		set_flag(5,1,0);
		set_state_continue(40);
		}
	if(get_flag(5,1) == 4) {
		set_flag(5,1,0);
		set_state_continue(50);
		}
	if(get_flag(5,1) == 5) {
		set_flag(5,1,0);
		set_state_continue(60);
		}


break;


beginstate 1; //EXIT_STATE

break;


beginstate 2; //START_STATE
	pc_counter = 0;
	while(char_ok(pc_counter) == 0) {
		pc_counter = pc_counter + 1;
		}
	lead_char = pc_counter;

	//Miali's poison
	if(get_flag(5,15) > 0) {
		inc_flag(5,15,1);
		if(get_flag(5,15) == 10)
			set_state_continue(33);
	}

break;


beginstate 10; //Ladder in the inn's cellar

	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",1);
		end();
		}

	reset_dialog();
	add_dialog_str(0,"There's a ladder here. Do you climb it?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	choice = run_dialog(1);

	if(choice == 1) 
		move_to_new_town(4,6,7);
	else
		block_entry(1);

break;


beginstate 11; //Ladder below the forge

	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",1);
		end();
		}
	
	if(char_ok(7) == 1) {
		block_entry(1);
		message_dialog("You can't leave while Private Stirlen is still down here!","");
		end();
		}

	reset_dialog();
	add_dialog_str(0,"There's a ladder here. Do you climb it?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	choice = run_dialog(1);
		
	if(choice == 1) 
		move_to_new_town(4,26,13);
	else
		block_entry(1);

break;


beginstate 12; //Ladder below the mayor's office

	reset_dialog();
	add_dialog_str(0,"There's a ladder here. Do you climb it?",0);
	add_dialog_choice(0,"Yes.");
	add_dialog_choice(1,"No.");
	choice = run_dialog(1);
	
	if(char_ok(6) == 1) {
		block_entry(1);
		message_dialog("The mayor is still just standing there, and you still have a job to do.","");
		end();
		}

	if(is_combat() == 1) {
		block_entry(1);
		print_str_color("You can't climb the ladder in combat mode.",1);
		end();
		}
	if(choice == 1) {
		if(get_flag(5,8) < 2) {
			reset_dialog();
			add_dialog_str(0,"As you emerge from the gloomy cellar that the mayor called home, you're a bit confused. Something in your gut tells you that there was something down there. You're not sure what, though.",0);
			add_dialog_str(1,"Either way, you don't want to go back down there, lest the ceiling collapse. And you had a strange feeling that you were being watched.",0);
			add_dialog_str(2,"Commander Ylissa probably won't be happy about this, but at least you tried.",0);
			run_dialog(1);
			}
		else if(get_flag(10,9) == 1) {
			reset_dialog();
			add_dialog_str(0,"The deed is done. The mayor is dead, and as long as you leave the body down here, nobody will ever have to know.",0);
			add_dialog_str(1,"You're grateful to leave the damp, ruined basement behind, particularly now that there's a body in it. When you climb out of the trapdoor, you decide to lock it behind you, so that nobody else can discover what you've done.",0);
			add_dialog_str(2,"You think that Commander Ylissa would love to know about this turn of events.",0);
			run_dialog(1);
			}
		else {
			reset_dialog();
			add_dialog_str(0,"Well, for better or worse, the deed is done. The mayor is gone, hopefully never to return. Maybe the rebels will get him, maybe he'll escape the province alive.",0);
			add_dialog_str(1,"Either way, you learned all you could from him, and you can relay the information to Commander Ylissa.",0);
			add_dialog_str(2,"You decide that it would be best to... well, not so much lie to the townspeople, but simply to not say anything about the mayor's disappearance. It will probably make your life a lot easier.",0);
			add_dialog_str(3,"Either way, you lock the trapdoor behind you, so that the townspeople will stay out of that unsafe basement...",0);
			run_dialog(1);
			}
		move_to_new_town(4,21,27);
		}
	else
		block_entry(1);

break;


beginstate 20; // Entering the inn's cellar

	if(get_flag(5,6) == 0)
		set_flag(5,0,get_ran(1,1,2));
	if((get_flag(5,0) == 1) || (get_flag(5,0) == 4) || (get_flag(5,0) == 3))
		set_terrain(10,11,125);

	force_instant_terrain_redraw();
	pause(10);

	if(get_flag(5,6) == 0) {
		reset_dialog();
		add_dialog_str(0,"Unsurprisingly, the cellar of the Sunken Cow has been trashed a bit. The ceiling held up surprisingly well. At least, it's mostly in one piece, and the two giant pillars that hold it up are intact.",0);
		add_dialog_str(1,"Anyway, thick layers of dust coat everything, and the floor is littered with small rocks and bits of broken boards.",0);
		add_dialog_str(2,"Finding anything down here is going to be difficult, but mostly just because the cellar is so poorly organized.",0);
		run_dialog(1);
		set_flag(5,6,1);
		}

break;


beginstate 21; //wine locker (or big rock)

	reset_dialog();
	if(get_flag(5,0) == 4) {
		add_dialog_str(0,"The slab is still here, and it doesn't look like you can move it or break it. Really, you're not sure what you'd do with the crushed cabinet anyway.",0);
		run_dialog(1);
		}
	if(get_flag(5,0) == 1) {
		add_dialog_str(0,"Hm... it looks like this huge slab of rock used to be part of the wall, and it crushed a cabinet. Whatever was in the cabinet must've met the same fate.",0);
		if(get_flag(4,12) == 0)
			add_dialog_str(1,"You detect a rather fruity smell in the air, and notice a puddle of what can only be wine on the dusty floor.",0);
		else
			add_dialog_str(1,"You're not terribly surprised to see a puddle on the ground around the slab, and even less surprised that it smells like rather nice wine. Karl probably won't be happy about this.",0);
		set_flag(5,0,4);
		run_dialog(1);
		}
	else if(get_flag(5,0) == 2) {
		add_dialog_str(0,"This cabinet has seen better days. It looks like it's several decades old, and the dank cellar hasn't done much for its appearance. And it's locked.",0);
		add_dialog_str(1,"A loud creak catches your attention, and you see that a rather large chunk of the wall is trying to fall out, and is barely being propped up by the old cabinet.",0);
		if(has_special_item(1) == 1) {
			add_dialog_str(2,"Fortunately, you have the key that Karl gave you, and are able to quickly unlock and open the cabinet, revealing a plain-looking bottle of what must be Karl's Solarian wine.",0);
			add_dialog_str(3,"Without thinking about traps, you grab the bottle, just in time to hear the wood of the cabinet splinter and crack. A huge section of wall falls onto the the cabinet, crushing it.",0);
			add_dialog_str(4,"You step back cautiously, just glad you didn't get killed. You did lose the key, but Karl probably won't care.",0);
			run_dialog(1);
			change_spec_item(2,1);
			change_spec_item(1,-1);
			set_flag(5,0,3);
			play_sound(108);
			set_terrain(10,11,125);
			force_instant_terrain_redraw();
			}
		else {
			add_dialog_str(2,"Regrettably, you don't have a quick way to open it, so when the section of wall falls onto the cabinet before your eyes, you're a little angry.",0);
			add_dialog_str(3,"When the cabinet was crushed, you thought you could hear a sound like breaking glass. You curse under your breath, assuming it was valuable.",0);
			if(get_flag(11,2) != 0)
				add_dialog_str(4,"Regardless of its value, you're sure that Karl would've liked to have it. And now, it's dust.",0);
			run_dialog(1);
			set_flag(5,0,4);
			play_sound(108);
			set_terrain(10,11,125);
			force_instant_terrain_redraw();
			}
		}

break;


beginstate 22; //searching for wine (specobj in the rubble)

	if((get_ran(1,1,50) >= 47) && (get_flag(5,5) <= 16)) {
		//find wine bottle
		print_str_color("You search the debris, and find an intact wine bottle.",4);
		reward_give(415);
		inc_flag(5,5,1);
		}
	else if(get_ran(1,1,50) >= 44) {
		//find smashed wine bottle
		print_str_color("You search the debris, and find a smashed wine bottle.",4);
		}
	else if(get_ran(1,1,50) >= 35) {
		//find trash
		print_str_color("You search the debris, finding only garbage.",4);
		}
	else if(get_ran(1,1,50) >= 30) {
		//find a rock
		print_str_color("You search the debris, and you find a rock.",4);
		reward_give(109);
		}
	else {
		//find nothing
		print_str_color("You search the debris, but find nothing.",4);
		}

break;


beginstate 30; // Entering town below the forge

	if(get_flag(5,2) == 0) {
		reset_dialog();
		if(get_flag(0,8) == 1) {
			add_dialog_str(0,"As you descend into what should be the forge, you're suddenly struck by a powerful wave of hot air. So, if nothing else, you know that the forge is still somewhat operational.",0);
			}
		else {
			add_dialog_str(0,"You weren't sure what to expect when you descended the ladder, but a blast of hot air quickly made you realize that you were climbing down into a forge. At a glance, it still looks somewhat operational.",0);
			}
		run_dialog(1);
		set_flag(5,2,1);
		}

	if(get_flag(5,3) == 0)
		set_state_continue(31); //Proceed to the opening cutscene

break;



beginstate 31; //Stirlen's cutscene with Miali

	//set everyone up
	if(get_flag(20,0) == 1) {
		activate_hidden_group(2);
		relocate_character(7,29,14);
		set_character_pose(7,2);
		set_name(7,"Private Stirlen");
		}
	activate_hidden_group(3);
	set_name(8,"Miali");
	relocate_character(8,29,13);
	set_character_pose(8,14);
	relocate_character(0,26,12);
	relocate_character(1,26,13);
	relocate_character(2,26,14);
	relocate_character(3,26,15);
	set_character_facing(1000,6);
	force_view_center(26,13);
	force_instant_terrain_redraw();
	pause(10);
	set_flag(5,3,1);

	reset_dialog();
	
	add_dialog_str(0,"Climbing down the ladder found beneath the trapdoor, you find yourself in the forge run by Iracos and Miali.",0);
	add_dialog_str(1,"Unsurprisingly, it's oppressively hot down here. That would be due to what looks like lava at the north end of the room. It must be maintained with magic.",0);
	add_dialog_str(2,"The ceiling of this room has collapsed in a few places, and the floor is generally covered in debris. In the part of the room closest to where the blast went off, there's a huge pile of rocks.",0);
	//if Stirlen got transferred (or if you don't know who he is), more text, then nothing
	if((get_flag(20,0) == 0) || (get_flag(2,16) == 2)) {
		reset_dialog();
		if(get_flag(11,1) == 1)
			add_dialog_str(3,"You also see Miali lying in the middle of the floor. She looks like she's hurt pretty badly... you should probably see if she's still alive.",0);
		else {
			add_dialog_str(3,"There's also a woman lying in the middle of the floor, and she looks like she's hurt pretty badly. You should probably see if she's still alive.",0);
			if((get_flag(4,29) == 1) || (get_flag(14,0) == 1) || (get_flag(0,6) == 1))
				add_dialog_str(4,"It's probably Iracos' wife Miali. He'd probably appreciate it if you saved her.",0);
			}
		run_dialog(1);
		pause(5);
		end();
		}
	add_dialog_str(3,"But that's not what catches your eye...",0);
	run_dialog(1);
	pause(5);
	force_view_center(29,13);
	force_instant_terrain_redraw();
	pause(5);
	
	//Off to the cutscene
	set_state_continue(32);
	
break;



beginstate 32; //cutscene with Stirlen

	reset_dialog();
	add_dialog_str(0,"A strange scene is set before you. There's a young soldier crouched over the prone body of an injured young woman, who seems to be breathing heavily.",0);
	add_dialog_str(1,"The soldier doesn't seem to notice your presence. He pulls out a waterskin and pours some water onto the woman's wounds in what looks like an attempt to clean them.",0);

	if(get_flag(2,13) < 2) {
		add_dialog_str(2,"It's hard to tell in the dim light, but the soldier looks an awful lot like the one who rushed past you on your way back to Hektos.",0);
		if(get_flag(11,1) == 1)
			add_dialog_str(3,"And unless you're mistaken, the woman he's attending to is Miali, Iracos' wife.",0);
		else if((get_flag(4,29) == 1) || (get_flag(14,0) == 1) || (get_flag(0,6) == 1))
			add_dialog_str(3,"So, unless you're mistaken, the woman he's attending to should be Miali, Iracos' wife.",0);
		else
			add_dialog_str(3,"The woman is completely unfamiliar to you, but whoever she is, she doesn't look to be hurt all that badly. At least not horribly so.",0);
		add_dialog_str(4,"Suddenly, you realize that the soldier is staring right at you... he finally noticed your intrusion.",0);
		}

	else {
		add_dialog_str(2,"It's hard to tell in the dim light, but the soldier looks an awful lot like Private Stirlen.",0);
		if(get_flag(11,1) == 1)
			add_dialog_str(3,"You feel your stomach turn a back-flip when you realize that the woman he's caring for is Miali. This could get ugly.",0);
		else if((get_flag(4,29) == 1) || (get_flag(14,0) == 1) || (get_flag(0,6) == 1))
			add_dialog_str(3,"So, unless you're mistaken, the woman he's attending to should be Miali, Iracos' wife. But with what you know about Stirlen, you fervently hope you're wrong.",0);
		else
			add_dialog_str(3,"The woman is completely unfamiliar to you, but you have a bad feeling that it's this Miali woman whom Stirlen told you about.",0);
		add_dialog_str(4,"Shortly after you realize that you've stumbled into a dangerously unstable room with a dangerously unstable soldier, Private Stirlen notices your presence.",0);
		}
	run_dialog(1);

	//Let the cutscene madness begin!!!

	pause(15);
	play_sound(18);
	set_character_facing(7,2);
	force_instant_terrain_redraw();
	pause(2);
	text_bubble_on_char(7,"Who goes there!");
	force_instant_terrain_redraw();
	pause(18);
	erase_text_bubbles();
	pause(5);
	if(get_flag(2,13) < 2) {
		set_character_pose(7,2);
		force_instant_terrain_redraw();
		text_bubble_on_char(7,"Private Stirlen, currently off duty!");
		force_instant_terrain_redraw();
		pause(18);
		play_sound(93);
		erase_text_bubbles();
		text_bubble_on_char(7,"Wait, it doesn't matter.");
		force_instant_terrain_redraw();
		pause(19);
		erase_text_bubbles();
		text_bubble_on_char(7,"I just want to know one thing.");
		force_instant_terrain_redraw();
		pause(19);
	}
	else {
		play_sound(93);
		set_character_pose(7,0);
		text_bubble_on_char(7,"Oh, it's you.");
		force_instant_terrain_redraw();
		pause(19);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(5);
		text_bubble_on_char(7,"Wait a minute.");
		force_instant_terrain_redraw();
		pause(20);
	}

	erase_text_bubbles();
	set_character_pose(7,1);
	text_bubble_on_char(7,"Why are you here?");
	force_instant_terrain_redraw();
	pause(17);
	erase_text_bubbles();
	text_bubble_on_char(7,"Why must you disturb me");
	force_instant_terrain_redraw();
	pause(18);
	erase_text_bubbles();
	text_bubble_on_char(7,"when I am alone with the woman I love?");
	force_instant_terrain_redraw();
	pause(21);
	erase_text_bubbles();
	set_character_facing(7,0);
	set_character_pose(7,0);
	text_bubble_on_char(7,"...Miali.");
	force_instant_terrain_redraw();
	pause(23);
	erase_text_bubbles();
	force_instant_terrain_Redraw();
	reset_dialog();
	if(((get_flag(4,29) == 1) || (get_flag(14,0) == 1) || (get_flag(0,6) == 1) || (get_flag(11,1) == 1)) && (get_flag(2,13) < 2))
		add_dialog_str(0,"Okay, that's bad. It's definitely Miali, and this man is definitely insane.",0);
	else if(get_flag(2,13) >= 2)
		add_dialog_str(0,"Okay, that's really, really bad. It's definitely Miali, and Stirlen is highly likely to do something regrettable.",0);
	else
		add_dialog_str(0,"Okay, you're starting to get really nervous about this soldier. Something just seems wrong.",0);
	run_dialog(1);

	pause(10);
	text_bubble_on_char(random_party_member(), "But she's hurt.");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	pause(10);
	text_bubble_on_char(7,"Yes, I know.");
	force_instant_terrain_redraw();
	pause(15);
	erase_text_bubbles();
	pause(5);
	text_bubble_on_char(random_party_member(), "But she might die.");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	pause(3);
	set_character_facing(7,2);
	force_instant_terrain_redraw();
	pause(2);
	text_bubble_on_char(7,"Yes, I know.");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	pause(5);
	reset_dialog();
	add_dialog_str(0,"You see Stirlen fingering the hilt of what looks like a dagger, tucked into his belt. At this point, you're really just hoping that this doesn't get any uglier.",0);
	run_dialog(1);
	pause(5);
	text_bubble_on_char(7,"So what do you plan on doing?");
	force_instant_terrain_redraw();
	pause(18);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	pause(5);
	set_character_facing(7,0);
	force_instant_terrain_redraw();
	pause(4);
	text_bubble_on_char(7,"You see, we're going to be together,");
	force_instant_terrain_redraw();
	pause(18);
	erase_text_bubbles();
	text_bubble_on_char(7,"and this is the only way.");
	force_instant_terrain_redraw();
	pause(19);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	pause(2);
	set_character_pose(7,2);
	force_instant_terrain_redraw();
	play_sound(18);
	pause(3);
	set_character_pose(7,1);
	force_instant_terrain_redraw();
	put_sparkles_on_char(8,7,1);
	run_animation_sound(69);
	set_character_pose(7,0);
	force_instant_terrain_Redraw();

	reset_dialog();
	add_dialog_str(0,"Before you can react, Stirlen draws the dagger and slashes Miali's wrist. Her body shudders violently, and she moans. A crazed smile spreads across the soldier's face.",0);
	add_dialog_str(1,"_Well, it's only a matter of time. There's a lot of poison on this blade, you know. So you can kill me now, if that's what you want. I know that's what I want. But she'll be coming with me._",0);
	add_dialog_str(2,"You bet that you can probably still save her, but you know that Stirlen will be trying to keep you from doing it. You'll have to take care of him first.",0);
	run_dialog(1);

	set_flag(5,4,1);

	//Let the fight begin, and set Miali's poison counter
	set_flag(5,15,1);

	
break;


beginstate 33; //Miali's poison-death

	reset_dialog();
	add_dialog_str(0,"Miali begins to moan, and for a moment, you think that she might be waking up. However, her body begins to convulse wildly.",0);
	add_dialog_str(1,"But then the shaking stops. It doesn't look like she's breathing anymore... it looks like you're too late.",0);
	if(char_ok(7) != 1)
		add_dialog_str(2,"You're not sure what bothers you more, the simple fact that she died, or the fact that it means she might be with Stirlen right now.",0);
	else
		add_dialog_str(2,"You're not sure what bothers you more, the simple fact that she died, or the fact that you have to kill Stirlen now. You might actually reunite them, god forbid.",0);
	run_dialog(1);
	set_flag(5,15,0);
	set_flag(10,1,1);
	play_sound(-21);
	erase_char(8);
	put_item_on_spot(29,13,447);
	force_instant_terrain_redraw();

break;


beginstate 34; //Saving Miali

	if(get_flag(5,3) == 1)
		begin_talk_mode(10);
	else
		begin_talk_mode(20);		

break;


beginstate 50; // Entering the hall of records

	if((get_flag(5,11) != 0) || (get_flag(5,12) != 0))
		set_terrain(get_flag(5,11),get_flag(5,12),130);
	if(get_flag(5,7) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you descend the ladder under the trapdoor, you're surprised by how far down this room is. With the lake so close, it would have taken a major feat of engineering to keep the water out.",0);
		add_dialog_str(1,"Then the first wave of dank air hits you. Maybe it wasn't as bad down here before the blasts, but it's clear that this room will rapidly become a lost cause. Even the few torches that light the room seem to be giving up.",0);
		add_dialog_str(2,"Pools of water have begun to form, fed by streams of water trickling out of the damaged walls. This can't be good for the piles of records that fill half of the room... they'll probably be lost rather soon.",0);
		add_dialog_str(3,"At the other end of the room, past what might've once been a wall, it looks like there was a well-furnished living room. Perhaps it was the mayor's room.",0);
		run_dialog(1);
		set_flag(5,7,1);
		}

break;


beginstate 51; //searching record piles

	reset_dialog();
	add_dialog_str(0,"It'd be a shame to see all of these documents go to waste, but you honestly don't know what you'd do with them. Hell, you wouldn't even know which ones to save... they all look like standard Empire paperwork.",0);
	add_dialog_str(1,"Reluctantly, you leave the papers alone.",0);
	run_dialog(1);

break;


beginstate 52; //entering mayor's quarters

	if(get_flag(5,9) == 0) {
		message_dialog("This side of the room was clearly designed for luxury, despite its rather dismal location. It looks very lived in, which makes you wonder just how much time the mayor spent here.","");
		set_flag(5,9,1);
		}

break;


beginstate 53; //book in desk (specobj trigger)

	if(get_flag(5,8) == 1) {
		reset_dialog();
		add_dialog_str(0,"The book is still here. Do you read it?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No.");
		choice = run_dialog(1);

		if(choice == 1)
			set_state_continue(54);

		}
	if(get_flag(5,8) == 0) {
		reset_dialog();
		add_dialog_str(0,"Looking in this battered desk, you find a surprisingly intact book. It's rather plain, with no title, a thin cover, and low quality paper. It doesn't even feel magical in any way.",0);
		add_dialog_str(1,"Do you read it?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No.");
		choice = run_dialog(1);
		set_flag(5,8,1);

		if(choice == 1)
			set_state_continue(54);

		}

break;


beginstate 54; //mayor's cutscene

		set_flag(5,8,2);
		if(party_size() == 1)
			message_dialog("You lay the book on top of the desk so you can get a better look at it.","");
		else
			message_dialog("You lay the book on top of the desk, so you can all crowd around it and see.","");
		//crowd the party around the book
		relocate_character(0,15,22);
		set_character_facing(0,0);
		relocate_character(1,16,22);
		set_character_facing(1,0);
		relocate_character(2,17,22);
		set_character_facing(2,0);
		relocate_character(3,17,21);
		set_character_facing(3,2);
		relocate_character(4,17,20);
		set_character_facing(4,2);
		force_view_center(16,21);
		force_instant_terrain_redraw();

		reset_dialog();
		add_dialog_str(0,"You flip open the book, and find that it's a journal, probably the mayor's. Instinctively, you flip to the latest entry, barely halfway through the book.",0);
		add_dialog_str(1,"It's time at last. I can't believe I'm doing this... they won't even let me evacuate the town. And if I refuse, well, it's the same threat as always. I just can't understand, these aren't the people I thought I'd be fighting alongside.",10);
		add_dialog_str(2,"They even want me to burn this. _Leave it near one of the bombs,_ Joshua said. _Nobody can know you were involved, or you're dead to us._",10);
		add_dialog_str(3,"Well, I pray that someone finds this, so that I may be free of my burden. Whoever reads this, heed my story.",10);
		add_dialog_str(4,"You barely finish reading the last line when you hear a sound from behind you.",0);
		run_dialog(1);
		
		pause(5);
		activate_hidden_group(1);
		set_character_facing(6,2);
		relocate_character(6,21,27);
		force_view_center(21,27);
		force_instant_terrain_redraw();
		play_sound(47); //Mayor's footsteps
		pause(10);
		relocate_character(6,20,27);
		force_view_center(20,27);
		force_instant_terrain_redraw();
		play_sound(47);
		pause(10);
		set_character_facing(6,0);
		relocate_character(6,20,26);
		force_view_center(20,26);
		set_character_facing(0,4);
		set_character_facing(1,4);
		set_character_facing(2,6);
		set_character_facing(3,6);
		force_instant_terrain_redraw();
		play_sound(47);
		pause(10);
		set_character_facing(6,2);
		force_instant_terrain_redraw();
		pause(15);

		//
		message_dialog("Alarmed by the mayor's sudden appearance, you pocket the book.","Torn between killing the man now and killing him after interrogating him, you freeze. But before you can do either, the mayor speaks.");
		change_spec_item(4,1);
		pause(10);
		text_bubble_on_char(6,"So, you found it.");
		force_instant_terrain_redraw();
		pause(18);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(5);
		text_bubble_on_char(6,"I'm glad, really.");
		force_instant_terrain_redraw();
		pause(18);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(5);
		text_bubble_on_char(6,"I wish it could've been sooner.");
		force_instant_terrain_redraw();
		pause(18);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(10);
		text_bubble_on_char(6,"What are you going to do?");
		force_instant_terrain_redraw();
		pause(18);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(5);
		
		set_flag(5,10,random_party_member()); //get someone mad
		force_view_center(char_loc_x(get_flag(5,10)), char_loc_y(get_flag(5,10)));

		if(party_size() != 1) {	

			set_character_facing(get_flag(5,10),4);
			set_character_pose(get_flag(5,10),1);
			force_instant_terrain_redraw();
			play_sound(-48);
			play_sound(18);
			pause(3);
			if(get_flag(5,10) == 0) {
				set_character_pose(1,2);
				set_character_facing(1,2);
			}
			if(get_flag(5,10) == 1) {
				set_character_pose(0,2);
				set_character_facing(0,6);
				set_character_pose(2,2);
				set_character_facing(2,2);
			}
			if(get_flag(5,10) == 2) {
				set_character_pose(1,2);
				set_character_facing(1,6);
				set_character_pose(3,2);
				set_character_facing(3,4);
			}
			if(get_flag(5,10) == 3) {
				set_character_pose(2,2);
				set_character_facing(2,0);
				set_character_pose(4,2);
				set_character_facing(4,4);
			}
			if(get_flag(5,10) == 4) {
				set_character_pose(3,2);
				set_character_facing(3,0);
			}
			force_instant_terrain_redraw();	
			reset_dialog();
			clear_buffer();
			append_char_name(get_flag(5,10));
			append_string(" suddenly screams, and draws a blade. You barely succeed in holding them back.");
			get_buffer_text(angry);
			add_dialog_str(0,angry,0);
			run_dialog(1);
			
			pause(5);
		}	
		text_bubble_on_char(get_flag(5,10),"Why?");
		force_instant_terrain_redraw();
		pause(13);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(3);	
		text_bubble_on_char(get_flag(5,10),"Why did you do it?");
		force_instant_terrain_redraw();
		pause(13);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(10);	
		text_bubble_on_char(get_flag(5,10),"How could you do that to those people?");
		force_instant_terrain_redraw();
		pause(16);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(8);
		text_bubble_on_char(get_flag(5,10),"Give me one good reason");
		force_instant_terrain_redraw();
		pause(16);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(2);
		text_bubble_on_char(get_flag(5,10),"why I shouldn't kill you right now.");
		force_instant_terrain_redraw();
		pause(16);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(10);
		text_bubble_on_char(6,"Well...");
		force_instant_terrain_redraw();
		pause(16);
		erase_text_bubbles();
		force_instant_terrain_redraw();

		//Mayor's plea
		reset_dialog();
		add_dialog_str(0,"The mayor draws a deep breath. He almost looks like he wants you to kill him.",0);
		add_dialog_str(1,"_You are working for the Empire now, correct?_ he asks. You nod, and he grimaces. _As I thought._",0);
		add_dialog_str(2,"_If you think that killing me will make these attacks stop, you are wrong. I was not alone in this act, and if you spare my life, then I will tell you what I know._",0);
		run_dialog(1);

		//Don't kill him yet, just for the investigation
		pause(5);
		reset_dialog();
		clear_buffer();
		if(party_size() > 1) {
			append_char_name(get_flag(5,10));
			append_string(" screams");
			}
		else
			append_string("You scream");
		append_string(" out several things that you'd normally never get to say to an Empire official without encountering the business end of an executioner's axe.");
		get_buffer_text(angry);
		add_dialog_str(0,angry,0);
		if(party_size() != 1)
			add_dialog_str(1,"However, you know that killing this slime  won't get you any closer to avenging the attack on Hektos, so you sheathe your weapons, reluctantly.",0);
		else
			add_dialog_str(1,"However, you know that killing this slime  won't get you any closer to avenging the attack on Hektos, so you stand down.",0);
		run_dialog(1);

		//Mayor's story (hint about final puzzle)
		pause(5);
		set_character_pose(1000,0);
		play_sound(93);
		force_instant_terrain_redraw();
		pause(5);
		reset_dialog();
		add_dialog_str(0,"_Good. You won't regret sparing me, I swear it,_ the mayor says, his voice shaking a bit.",0);
		add_dialog_str(1,"_As you might know by now, there are rebels in this valley. I'd known it for years, and I'd secretly prayed for their victory. I never actually aided them, just let them go about their business unhindered._",0);
		add_dialog_str(2,"_I dreamed of helping them in their noble quest to topple the Empire, until one day one of them walked into my office. He looked unassuming, but he proceeded to threaten me at swordpoint._",0);
		add_dialog_str(3,"_He pressed me into helping them with their most ambitious plot yet. They would attack a town, drawing Empire troops in to aid the survivors._",0);
		add_dialog_str(4,"_Then, once the valley was full of soldiers and officials, they would strike again._",0);
		run_dialog(1);

		pause(5);
		text_bubble_on_char(get_flag(5,10),"What are they planning?");
		force_instant_terrain_redraw();
		pause(16);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(15);
		text_bubble_on_char(get_flag(5,10),"TELL ME!");
		force_instant_terrain_redraw();
		pause(16);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(5);
		text_bubble_on_char(6,"I... I don't know.");
		force_instant_terrain_redraw();
		pause(21);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(3);

		//Kill or release?
		reset_dialog();
		add_dialog_str(0,"_They never told me,_ he says sadly. _I don't think I even want to know. I wish I'd never gotten involved in this, and I need to get out._",0);
		add_dialog_str(1,"He sighs. _And now you know the story. At least you can do something before they finish their plans... I couldn't._",0);
		add_dialog_str(2,"_I always loved this valley, I never lied about that. I hate myself for what I've become, and thus I place my fate in your hands._",0);
		add_dialog_str(3,"_If you spare me, I'll leave and never return. If you choose otherwise... well, I deserve it,_ he says, choking a bit.",0);
		add_dialog_str(4,"What do you do?",0);
		add_dialog_choice(0,"Kill him.");
		add_dialog_choice(1,"Spare him.");
		choice = run_dialog(1);

		if(choice == 1) {
			
			reset_dialog();
			add_dialog_str(0,"An uncomfortable silence descends as the mayor realizes that you're not going to let him go. He hangs his head.",0);
			add_dialog_str(1,"You can barely look the man in the face, a mix of pity and anger brewing as you prepare to draw a blade.",0);
			run_dialog(1);
			set_mobility(6,0);
			}
		else {
			pause(15);
			text_bubble_on_char(get_flag(5,10),"Go.");
			force_instant_terrain_redraw();
			pause(13);
			erase_text_bubbles();
			force_instant_terrain_redraw();
			pause(2);
			text_bubble_on_char(get_flag(5,10),"Get the hell out of here,");
			force_instant_terrain_redraw();
			pause(16);
			erase_text_bubbles();
			text_bubble_on_char(get_flag(5,10),"and never come back.");
			force_instant_terrain_redraw();
			pause(16);
			erase_text_bubbles();
			force_instant_terrain_redraw();
			pause(3);
			text_bubble_on_char(get_flag(5,10),"Understand?");
			force_instant_terrain_redraw();
			pause(14);
			erase_text_bubbles();
			force_instant_terrain_redraw();
			pause(5);
			text_bubble_on_char(6,"...");
			force_instant_terrain_redraw();
			pause(16);
			erase_text_bubbles();
			force_instant_terrain_redraw();
			pause(2);
			reset_dialog();
			add_dialog_str(0,"The mayor looks as if he's about to cry. In a strained, weak voice, he mutters two words before losing his composure... _Thank you._",0);
			add_dialog_str(1,"And with that, he turns and runs.",0);
			run_dialog(1);
			relocate_character(6,20,27);
			set_character_facing(6,4);
			force_instant_terrain_redraw();
			play_sound(47);
			pause(2);
			relocate_character(6,21,27);
			set_character_facing(6,6);
			force_instant_terrain_redraw();
			play_sound(47);
			pause(2);
			relocate_character(6,22,27);
			force_instant_terrain_redraw();
			play_sound(47);
			pause(2);
			erase_char(6);
			force_view_center(char_loc_x(lead_char), char_loc_y(lead_char));
			set_character_pose(1000,0);
			force_instant_terrain_redraw();

			set_flag(10,9,2);
			reset_dialog();
			add_dialog_str(0,"The mayor has left the room, leaving you down here amidst the watery debris. It's getting a bit uncomfortable, in fact.",0);
			add_dialog_str(1,"You should probably report this to the Commander at Fort Galima... but you're not sure how honest to be about it. Something to think about on the way over, you decide.",0);
			run_dialog(1);
			}

break;




beginstate 56; //the painting in the mayor's quarters (specobj)

	reset_dialog();
	add_dialog_str(0,"This is a rather nice painting of Hektos, pre-explosion. The water has damaged it a little bit.",0);
	add_dialog_str(1,"Your adventurer's senses start kicking in, and you search the painting, the wall behind the painting, and the frame of the painting for anything out of the ordinary.",0);
	add_dialog_str(2,"Unfortunately, you find nothing.",0);
	run_dialog(1);

break;


beginstate 57; //the tapestry in the mayor's quarters (specobj)

	reset_dialog();
	add_dialog_str(0,"This is a rather nice tapestry.",0);
	add_dialog_str(1,"Your adventurer's senses start kicking in, and you search the tapestry, and the wall behind it, in the hopes of finding... well, anything suspicious. Maybe a secret passage or something.",0);
	add_dialog_str(2,"Unfortunately, you find nothing.",0);
	run_dialog(1);

break;


beginstate 58; //the bed in the mayor's quarters (specobj)

	reset_dialog();
	add_dialog_str(0,"This is a rather nice bed. You take a moment to think about how it was brought down here.",0);
	add_dialog_str(1,"Your adventurer's senses start kicking in, and you search the bed, the linens (which haven't been changed in weeks), and the bed's frame for anything out of the ordinary.",0);
	add_dialog_str(2,"Unfortunately, you find nothing.",0);
	run_dialog(1);

break;